<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>

<template>
  <div>
    <div style="float:right ;margin-right:20px">
      <h5>未接种人数:{{ list.length }}</h5>
    </div>

    <div class="about" align="center">
      <el-table
        :data="
          list
            .filter(
              (data) =>
                !search ||
                data.shenfen.toLowerCase().includes(search.toLowerCase()) ||
                data.name.toLowerCase().includes(search.toLowerCase())
            )
            .slice((currentPage - 1) * pagesize, currentPage * pagesize)
        "
        style="width: 90%"
      >
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="姓名">
                <span>{{ props.row.name }}</span>
              </el-form-item>
              <el-form-item label="性别">
                <span>{{ props.row.sex }}</span>
              </el-form-item>
              <el-form-item label="年龄">
                <span>{{ props.row.age }}</span>
              </el-form-item>
              <el-form-item label="出生日期">
                <span>{{ props.row.chudata }}</span>
              </el-form-item>
              <el-form-item label="户籍地址">
                <span>{{ props.row.dizhi }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>

        <el-table-column
          label="序号"
          type="index"
          align="center"
          width="100"
        ></el-table-column>
        <el-table-column label="编号" prop="id" width="100"></el-table-column>
        <el-table-column label="姓名" prop="name" width="100"></el-table-column>
        <el-table-column label="身份证号" prop="shenfen"></el-table-column>
        <el-table-column label="联系电话" prop="phone"></el-table-column>

        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === 1" type="info">已接种</el-tag>
            <el-tag v-if="scope.row.status === 0" type="danger">未接种</el-tag>
          </template>
        </el-table-column>

        <el-table-column align="center">
          <template slot="header" slot-scope="scope">
            <el-input
              v-if="scope"
              v-model="search"
              size="mini"
              placeholder="输入关键字搜索"
            />
          </template>
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="change1(scope.row)"
              >确认接种</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 5, 20, 50]"
        :total="list.length"
        :page-size="0"
        layout=" sizes,prev,pager,next,jumper"
      >
      </el-pagination>
    </div>

    <div>
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose"
      >
        <span>是否确认接种？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button
            type="primary"
            @click="(dialogVisible = false), handleEdit()"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],

      //分页
      currentPage: 1,
      pagesize: 10,

      currentUser: {},
      //搜索
      search: "",
      //对话框
      dialogVisible: false,
    };
  },

  created() {
    this.query();
  },
  methods: {
    //分页
    handleSizeChange: function (size) {
      this.pagesize = size;
      console.log(this.pagesize); //每页下拉显示数据
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
      console.log(this.currentPage); //点击第几页
    },
    userlist() {
      this.$http.get("http://localhost:3000/users").then((res) => {
        this.list = res.body;
      });
    },

    //修改
    change1(row) {
      this.dialogVisible = true;
      this.currentUser = row;
    },
    handleEdit() {
      this.currentUser.status = 1;

      this.$api_j.__api_list_put(this.currentUser).then((data) => {
        this.query();
      });
    },
    //对话框
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },

    //刷新
    query() {
      this.$api_j.__api_list_users(this.pager).then((data) => {
        this.list = data;
        console.log(this.list);
      });
    },
  },
};
</script>
